<template>
	<view>
		<u-sticky bgColor="#fff">
			<u-tabs :list="tabs" :current="current" :scrollable="false" @change="onTabChange" lineColor="#ff820d"
				:activeStyle="{ color: '#ff820d' }"></u-tabs>
		</u-sticky>
		<block v-if="list.length>0">
			<view class="order_item" v-for="(item,i) in list" :key="item.id">
				<view class="head">
					<view class="order_num text-overflow1">订单号：{{item.order_sn}}</view>
					<view class="order_status">
						<u-tag text="已预订" plain size="mini" v-if="item.status==1"></u-tag>
						<u-tag text="交接中" plain size="mini" type="warning" v-else-if="item.status==2"></u-tag>
						<u-tag text="已完成" plain size="mini" type="success" v-else-if="item.status==3"></u-tag>
					</view>
				</view>
				<view class="order_info">
					<view class="title">{{item.title}}</view>
					<view class="hy">所属行业：{{item.industry}}</view>
					<view class="order_money">
						<view class="cj_price">成交价：{{item.price}}</view>
						<view class="dj">定金：{{item.dingjin}}</view>
					</view>
					<view class="weikuan">
						<text>尾款：{{item.weikuan}}</text>
						<u-tag text="不开票" plain size="mini" type="info" v-if="item.fapiao==0"></u-tag>
						<u-tag text="增值税普票" plain size="mini" type="warning" v-if="item.fapiao==2"></u-tag>
						<u-tag text="增值税专票" plain size="mini" type="error" v-if="item.fapiao==3"></u-tag>
					</view>
					<view class="all_price">总计应付：<text class="red">{{item.price}}</text>元</view>

					<view class="time">下单时间：{{$u.timeFormat(item.createtime, 'yyyy/mm/dd hh:MM')}}</view>

				</view>
				<view class="btnGroup">
					<view class="btn pay" v-if="item.weikuan!==0" @click="pay(item.zid)">支付尾款</view>
					<view class="btn contract" v-if="item.hetong==0" @click="contractClick(item.id)">签订合同</view>
				</view>
			</view>

		</block>
		<u-empty mode="order" icon="http://cdn.uviewui.com/uview/empty/order.png" v-else>
		</u-empty>
	</view>
</template>

<script>
	import {
		getOrder,
		payWeiKuan,
		getContract
	} from '@/config/api.js'
	export default {
		data() {
			return {
				tabs: [{
					name: '全部',
				}, {
					name: '已预定',
				}, {
					name: '交接中'
				}, {
					name: '已完成'
				}, ],
				current: 0,
				page: 1,
				list: [],
				nomore: false
			};
		},
		onLoad(op) {

			this.current = Number(op.type)
			this.getOrderList()
		},
		methods: {
			onTabChange(e) {
				this.current = e.index
				this.getOrderList()
			},
			async getOrderList() {
				uni.showLoading({
					mask: true,
					title: '加载中'
				})
				const res = await getOrder({
					act: this.current
				})
				uni.hideLoading()
				if (res.code == 1) {
					this.list = res.data
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			},
			// 支付尾款
			async pay(zid) {
				uni.showLoading({
					mask: true,
					title: '拉起支付中'
				})
				const res = await payWeiKuan({
					zid
				})
				uni.hideLoading()
				if (res.code == 1) {
					uni.showToast({
						icon: 'none',
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								this.list = []
								this.getOrderList()
							}, 1000)
						}
					})
				}
			},
			// 签订合同
			async contractClick(order_id) {
				uni.showLoading({
					mask: true,
					title: '获取合同中'
				})
				const res = await getContract({
					order_id,
					clientType: 'H5'
				})
				uni.hideLoading()
				console.log(res);
				if (res.code == 1) {

				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			}
		},
		watch: {
			// current(nV, oV) {
			// 	console.log(nV, oV);
			// }
		}
	}
</script>
<style>
	page {
		background-color: #f8f8f8;
	}
</style>
<style lang="scss">
	.order_item {
		margin: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;
		// border: 1px solid #ccc;
		padding: 30rpx;
		font-size: 24rpx;
		color: #333;

		.head {
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1px solid #eee;
			padding-bottom: 20rpx;

			.order_status {}

		}

		.order_info {
			.title {
				font-size: 32rpx;
				font-weight: 600;
				margin-top: 20rpx;
			}

			.hy {
				font-size: 26rpx;
				color: #666;
				margin-top: 20rpx;
			}

			.all_price {
				margin-top: 20rpx;

				.red {
					font-size: 36rpx;
					color: #ff0000;
					font-weight: 600;
				}
			}

			.time {
				margin-top: 20rpx;
			}



			.order_money {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 20rpx;
				white-space: nowrap;


			}

			.weikuan {
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}


		}

		.btnGroup {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			margin-top: 20rpx;
			padding-top: 20rpx;
			border-top: 1px solid #eee;

			.btn {
				width: 120rpx;
				height: 50rpx;
				border-radius: 15rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
			}

			.pay {
				background-color: $uni-color-success;
			}

			.contract {
				background-color: #2b85e4;
				margin-left: 20rpx;
			}
		}
	}
</style>